#include "Command.h"

/* Constructor */
Command::Command(byte type, byte deviceId, byte value)
{
  m_type = type;
  m_typeIsSet = true;
  m_deviceId = deviceId;
  m_deviceIdIsSet = true;
  m_value = value;
  m_valueIsSet = true;
}
Command::Command()
{
  m_typeIsSet = false;
  m_deviceIdIsSet = false;
  m_valueIsSet = false;
}

/* METHODES */
/**
* \brief Serialize Command data
* \param byte array
* \return none
*/
void Command::serialize(byte* serializedData)
{
  serializedData[0] = m_type;
  serializedData[1] = m_deviceId;
  serializedData[2] = m_value;
}

/**
* \brief Add a byte in command
* \param newByte
* \return endOfCommand
*/
boolean Command::addByte(byte newByte)
{
  boolean endOfCommand = false;
  if (m_typeIsSet == false)
  {
    m_type = newByte;
    m_typeIsSet = true;
  }
  else
  {
    if (m_deviceIdIsSet == false)
    {
      m_deviceId = newByte;
      m_deviceIdIsSet = true;
    }
    else
    {
      if (m_valueIsSet == false)
      {
        m_value = newByte;
        m_valueIsSet = true;
        endOfCommand = true;
      }
      else
      {
        /* ERROR, too many bytes added */
      }
    }
  }
  return endOfCommand;
}

/**
* \brief Return the type of command
* \param none
* \return m_type
*/
byte Command::getType()
{
  return m_type;
}

/**
* \brief Return the deviceId of command
* \param none
* \return m_deviceId
*/
byte Command::getDeviceId()
{
  return m_deviceId;
}

/**
* \brief Return the value of command
* \param none
* \return m_value
*/
byte Command::getValue()
{
  return m_value;
}
